﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[DisallowMultipleComponent]
public class PerObjectMaterialProperties : MonoBehaviour
{
    static int _baseColorId = Shader.PropertyToID("_BaseColor");
    static MaterialPropertyBlock _block;

    [SerializeField]
    Color _baseColor = Color.white;

    private void Awake()
    {
        OnValidate();
    }


    private void OnValidate()
    {
        if(_block == null)
        {
            _block = new MaterialPropertyBlock();
        }
        _block.SetColor(_baseColorId, _baseColor);
        gameObject.GetComponent<Renderer>().SetPropertyBlock(_block);
    }
}
